package com.kfm.springboot.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kfm.springboot.model.Account;
import com.kfm.springboot.service.AccountService;
import com.kfm.springboot.mapper.AccountMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author 10854
* @description 针对表【account】的数据库操作Service实现
* @createDate 2023-05-20 10:38:45
*/
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account>
    implements AccountService{


    @Override
    @Transactional
    public void transfer(Integer from, Integer to, Double money) {
        Account fromAccount = getById(from);
        Account toAccount = getById(to);

        fromAccount.setMoney(fromAccount.getMoney() - money);
        toAccount.setMoney(toAccount.getMoney() + money);
        updateById(fromAccount);
        int i = 3 / 0;
        updateById(toAccount);
    }
}




